package pl.nazaweb.imedproplus.model.entity;

import pl.nazaweb.imedproplus.model.interfaces.IReferral;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

@Entity
@Table(name = "referral")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Referral.findAll", query = "SELECT r FROM Referral r"),
    @NamedQuery(name = "Referral.findById", query = "SELECT r FROM Referral r WHERE r.id = :id"),
    @NamedQuery(name = "Referral.findByType", query = "SELECT r FROM Referral r WHERE r.type = :type"),
    @NamedQuery(name = "Referral.findByIssuanceDate", query = "SELECT r FROM Referral r WHERE r.issuanceDate = :issuanceDate"),
    @NamedQuery(name = "Referral.findByDoctor", query = "SELECT r FROM Referral r WHERE r.doctor = :doctor")})
public class Referral implements Serializable, IReferral {

    @Basic(optional = false)
    @NotNull
    @Column(name = "issuance_date")
    @Temporal(TemporalType.DATE)
    private Date issuanceDate;
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @SequenceGenerator(name = "referral_sequence_", sequenceName = "referral_sequence", allocationSize=1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "referral_sequence_")
    @NotNull
    @Column(name = "id")
    private Long id;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 10)
    @Column(name = "type")
    private String type;
    @Basic(optional = false)
    @NotNull
    @Column(name = "doctor")
    private long doctor;
    @JoinColumn(name = "patient", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Patient patient;
    @JoinColumn(name = "institution", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Institution institution;
    @JoinColumn(name = "diagnosis", referencedColumnName = "code")
    @ManyToOne
    private Icd10 diagnosis;
    @OneToMany(mappedBy = "referral")
    private List<Visit> visitList;

    public Referral() {
    }

    public Referral(Long id) {
        this.id = id;
    }

    public Referral(Long id, String type, Date issuanceDate, long doctor) {
        this.id = id;
        this.type = type;
        this.issuanceDate = issuanceDate;
        this.doctor = doctor;
    }

    @Override
    public Long getId() {
        return id;
    }

    @Override
    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public String getType() {
        return type;
    }

    @Override
    public void setType(String type) {
        this.type = type;
    }

    @Override
    public Date getIssuanceDate() {
        return issuanceDate;
    }

    @Override
    public void setIssuanceDate(Date issuanceDate) {
        this.issuanceDate = issuanceDate;
    }

    @Override
    public long getDoctor() {
        return doctor;
    }

    @Override
    public void setDoctor(long doctor) {
        this.doctor = doctor;
    }

    @Override
    public Patient getPatient() {
        return patient;
    }

    @Override
    public void setPatient(Patient patient) {
        this.patient = patient;
    }

    @Override
    public Institution getInstitution() {
        return institution;
    }

    @Override
    public void setInstitution(Institution institution) {
        this.institution = institution;
    }

    @Override
    public Icd10 getDiagnosis() {
        return diagnosis;
    }

    @Override
    public void setDiagnosis(Icd10 diagnosis) {
        this.diagnosis = diagnosis;
    }

    @XmlTransient
    @Override
    public List<Visit> getVisitList() {
        return visitList;
    }

    @Override
    public void setVisitList(List<Visit> visitList) {
        this.visitList = visitList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Referral)) {
            return false;
        }
        Referral other = (Referral) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "pl.nazaweb.imedproplus.model.entity.Referral[ id=" + id + " ]";
    }
}
